package com.qasystem.qa.core.service;

import com.qasystem.qa.core.constants.Constants;
import org.omg.CORBA.OBJECT_NOT_EXIST;
import org.springframework.boot.autoconfigure.cache.CacheProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Service
public class RedisService  {
    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    public void set (String key, Object value) {
        RedisSerializer redisSerializer = new StringRedisSerializer();
        redisTemplate.setKeySerializer(redisSerializer);
        ValueOperations<String, Object> vo = redisTemplate.opsForValue();
        vo.set(key, value, Constants.MAX_TIME, TimeUnit.SECONDS);
    }
    public Object get(String key) {
        ValueOperations<String, Object> vo = redisTemplate.opsForValue();
        return vo.get(key);
    }

    public  boolean delete (String key) {
        return redisTemplate.delete(key);
    }
}
